//机龄分析
var datajlfx = [];
//租赁性质分析
var dataFjzlxz = [];
var fjzlxzType = [];
//飞机型号分析
var fjxhfxlegend = [];
var fjxhfxnf = [];
var fjxhfxdata = [];
//飞机引进分析
var fjyjfxnf = [];
var fjyjfxYjdata = [];
var fjyjfxTcdata = [];

//机龄分析
var myChartJlfx = echarts.init(document.getElementById('jlfx'));
//飞机引进分析
var myChartFjyjfx = echarts.init(document.getElementById('fjyjfx'));
//飞机型号分析
var myChartFjxhfx = echarts.init(document.getElementById('fjxhfx'));
//飞机租赁性质分析
var myChartFjzlxzfx = echarts.init(document.getElementById('fjzlxzfx'));

//机龄分析
$.ajax({
	type: "GET",
	url: basePath + '/service/cxtj/getJlfxList',
	async:false,
    dataType: "json",
    success: function(data){
    	if(data.length > 0){
    		datajlfx.push(
    			{name: '0-5年', value: data[0].zerotofive},
    			{name: '5-10年', value: data[0].fivetoten},
    			{name: '10-15年', value: data[0].tentofifteen}
    		)
    	}
    }
})
//飞机租赁性质分析
$.ajax({
	type: "GET",
	url: basePath + '/service/cxtj/getFjzlxzList',
	async:false,
    dataType: "json",
    success: function(data){
    	if(data.length > 0){
    		for(var i=0;i<data.length;i++){
    			fjzlxzType.push(data[i].nature);
    			dataFjzlxz.push({
    				name:data[i].nature,
    				value:data[i].num
    			})
    		}
    	}
    }
})

//飞机型号分析
$.ajax({
	type: "GET",
	url: basePath + '/service/cxtj/fjxhfx',
	async:false,
    dataType: "json",
    success: function(data){
    	if(data.length > 0){
    		for(var i=0;i<data.length;i++){
    			fjxhfxnf.push(data[i].nf);
    			if(i == 0) {
    				for(var key in data[i]){
    					if(key != "nf" && key != "allNum"){
    						fjxhfxlegend.push(key)
    					}
    				}
    			}
    		}
    		for(var i=0;i<fjxhfxlegend.length;i++){
    			var obj = {};
    			var datalist = [];
    			obj.name = fjxhfxlegend[i];
    			obj.type = 'bar';
				obj.stack = '总量';
				obj.label = {show: true,position: 'insideRight'};
				for(var j=0;j<data.length;j++){
					for(var key in data[j]){
    					if(key == fjxhfxlegend[i]){
    						datalist.push(data[j][key]);
    					}
    				}
    	        }
				obj.data = datalist;
				fjxhfxdata.push(obj);
    		}
    		console.log(fjxhfxdata);
    	}
    }
})

//飞机引进分析
$.ajax({
	type: "GET",
	url: basePath + '/service/cxtj/fjyjfx',
	async:false,
    dataType: "json",
    success: function(data){
    	if(data.length > 0){
    		for(var i=0;i<data.length;i++){
    			fjyjfxnf.push(data[i].nf);
    			fjyjfxYjdata.push(data[i].yj)
    			fjyjfxTcdata.push(data[i].tc)
    		}
    	}
    }
})


var optionJlfx = {
		tooltip: {
	        trigger: 'item',
	        formatter: '{a} <br/>{b}: {c} ({d}%)'
	    },
	    legend: {
			type: 'scroll',
			orient: 'vertical',
			left: 10,
	        data: ['0-5年','5-10年','10-15年','15年以上']
	    },
	    series: [
	        {
	            name: '飞机机龄',
	            type: 'pie',
	            radius: ['50%', '70%'],
	            avoidLabelOverlap: false,
	            label: {
	                show: false,
	                position: 'center'
	            },
	            emphasis: {
	                label: {
	                    show: true,
	                    fontSize: '30',
	                    fontWeight: 'bold'
	                }
	            },
	            labelLine: {
	                show: false
	            },
	            data:datajlfx
	        }
	    ]
   };


var optionFjyjfx = {
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        }
	    },
	    legend: {
	    	data: ['退出', '引进']
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis: [
	        {
	            type: 'value'
	        }
	    ],
	    yAxis: [
	        {
	            type: 'category',
	            axisTick: {
	                show: false
	            },
	            data: fjxhfxnf
	        }
	    ],
	    series: [
	        {
	            name: '引进',
	            type: 'bar',
	            stack: '总量',
	            label: {
	                show: true
	            },
	            data: fjyjfxYjdata
	        },
	        {
	            name: '退出',
	            type: 'bar',
	            stack: '总量',
	            label: {
	                show: true,
	                position: 'left'
	            },
	            data: fjyjfxTcdata
	        }
	    ]
	};

var optionFjxhfx = {
	    tooltip: {
	        trigger: 'axis',
	        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
	            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
	        }
	    },
	    legend: {
	        data: fjxhfxlegend
	    },
	    grid: {
	        left: '3%',
	        right: '4%',
	        bottom: '3%',
	        containLabel: true
	    },
	    xAxis: {
	        type: 'value'
	    },
	    yAxis: {
	        type: 'category',
	        data: fjxhfxnf
	    },
	    series: fjxhfxdata
	};

var optionFjzlxzfx = {
		tooltip: {
	        trigger: 'item',
	        formatter: '{a} <br/>{b}: {c} ({d}%)'
	    },
	    legend: {
			type: 'scroll',
			orient: 'vertical',
			left: 10,
	        data: fjzlxzType
	    },
	    series: [
	        {
	            name: '租赁性质',
	            type: 'pie',
	         /*   avoidLabelOverlap: false,
	            label: {
	                show: false,
	                position: 'center'
	            },*/
	            emphasis: {
	                label: {
	                    show: true,
	                    fontSize: '30',
	                    fontWeight: 'bold'
	                }
	            },
	            labelLine: {
	                show: false
	            },
	            data:dataFjzlxz
	        }
	    ]
   };



myChartJlfx.setOption(optionJlfx);
myChartFjyjfx.setOption(optionFjyjfx);
myChartFjxhfx.setOption(optionFjxhfx);
myChartFjzlxzfx.setOption(optionFjzlxzfx);